package vitaliy.bondar.diamondcave;

import org.andengine.entity.Entity;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.text.Text;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

public class LevelBox extends Entity
{
	private boolean m_isOpened;
	private int m_levelNumber;
	private final Sprite m_locked;
	private final Sprite m_opened;
	private Text m_label;
	
	public LevelBox(final float x, final float y, 
			final VertexBufferObjectManager vbom) 
	{
		m_locked = new Sprite(x, y, ResourcesManager.getInstance().locked_region, vbom);
		m_opened = new Sprite(x, y, ResourcesManager.getInstance().level_icon_region, vbom);
		
		m_label = new Text(x, y + 28, ResourcesManager.getInstance().font, "0123456789", vbom);
		
		this.attachChild(m_locked);
		this.attachChild(m_opened);
		this.attachChild(m_label);
		
		this.m_isOpened = true;
		this.setOpened(false);
	}

	public void setOpened(boolean set)
	{
		if (m_isOpened == set) return;
		m_isOpened = set;
		m_locked.setVisible(!set);
		m_opened.setVisible(set);
	}
	
	public final boolean isOpened()
	{
	    return m_isOpened;
	}
	
	public void setLevelNumber(int level)
	{
		int offset;
		
	    if (level < 10) 
	    {
			offset = 32;
		} else {
            offset = 20;
        }
		
		m_levelNumber = level;
		m_label.setX(m_locked.getX() + offset);
		m_label.setText(String.valueOf(level));
	}
	
	public final int levelNumber()
	{
		return m_levelNumber;
	}
	
	public static int getHeight()
	{
		return (int)ResourcesManager.getInstance().locked_region.getHeight();
	}
	
	public static int getWidth()
	{
		return (int)ResourcesManager.getInstance().locked_region.getWidth();
	}

	public boolean contains(float x, float y) 
	{
		return m_locked.contains(x, y);
	}
	
	public void onClick()
	{}
}
